Linux Centos6.5安装python3

发布 : 2017-04-22 分类 : Linux 浏览 :

1.准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件)

1
yum install zlib-devel bzip2-devel  openssl-devel ncurses-devel

2.下载Python3.5代码包

1
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz

3.编译

1
2
3
4
tar -zxvf Python-3.5.2.tgz
cd Python-3.5.2
./configure --prefix=/usr/local/python3
make && make install

4.设置环境变量

1
echo 'export PATH=$PATH:/usr/local/python3/bin' >> ~/.bashrc

5.直接替换python2

1
2
3
4
rm -rf /usr/bin/python
ln -sv /usr/local/python3/bin/python3.5 /usr/bin/python
这样做的目的是在系统任意目录敲入python调用的是python3的命令,而非系统默认2.6.6的
但是这样同时这会导致依赖python2.6的yum不能使用,因此还要修改yum配置。

6.更新yum配置

1
2
3
ll /usr/bin | grep python
这时/usr/bin目录下面是包含以下几个文件的(ll |grep python)
其中有个python2.6,只需要指定yum配置的python指向这里即可
1
2
3
4
[root@VM-2-2 Python-3.5.2]# ll /usr/bin | grep python
lrwxrwxrwx 1 root root 24 6月 6 14:45 python -> /usr/local/bin/python3.5
lrwxrwxrwx 1 root root 6 4月 5 10:12 python2 -> python
-rwxr-xr-x 1 root root 4864 8月 18 2016 python2.6
1
2
3
4
vim /usr/bin/yum
通过vim修改yum的配置
#!/usr/bin/python改为#!/usr/bin/python2.6,保存退出。
完成了python3的安装。

7.安装setuptools包

1
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz

7.1.解压setuptools包

1
2
tar zxvf setuptools-2.0.tar.gz
cd setuptools-2.0

7.2.编译setuptools

1
python setup.py build

7.3.执行setuptools安装

1
python setup.py install

8.Linux上安装pip包管理器

8.1.下载压缩文件

1
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz

8.2.pip安装

1
2
3
tar -zxvf pip-1.5.4.tar.gz
cd pip-1.5.4
python setup.py install
1
2
3
Installing pip3.5 script to /usr/local/python3/bin
Installing pip3 script to /usr/local/python3/bin
Installing pip script to /usr/local/python3/bin

建立软链接

1
ln -sv /usr/local/python3/bin/pip /usr/bin/pip

8.3.pip安装包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pip install SomePackage

pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ Flask-Script
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ Flask-SQLAlchemy
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ PyMySQL
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ openpyxl
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ numpy
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ mysqlclient
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ mysql-connector
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ matplotlib
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ lxml
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ nltk
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ scikit-learn
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ pandas
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ scipy
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ xlrd
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ xlwt
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ redis
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ request
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ gevent
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ MySQL-python
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ Crypto
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ babel
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ pillow
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ Cython
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ Bottleneck
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ wheel

8.4.pip查看已安装的包

1
pip show --files SomePackage

8.5.pip检查哪些包需要更新

1
pip list --outdated

8.6.更新pip

1
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ -U pip

8.7.查看安装的包

1
pip list

8.8.安装过程中遇到的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@VM-2-2 ~]# pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ MySQL-python
Collecting MySQL-python
Downloading https://mirrors.ustc.edu.cn/pypi/web/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
100% |████████████████████████████████| 112kB 1.5MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-w4528i7v/MySQL-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/tmp/pip-build-w4528i7v/MySQL-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-w4528i7v/MySQL-python/
# 解决方法
[root@VM-2-2 ~]# pip install --upgrade setuptools
[root@VM-2-2 ~]# pip install ez_setup
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ unroll

pip install MySQL-python
本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2017/04/22/Linux Centos6.5安装python3/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹